
import axios from 'axios'

axios.defaults.timeout = 2500;

//设置请求拦截器
axios.interceptors.request.use(function (config) {
    // Do something before request is sent
    return config;
}, function (error) {
    // Do something with request error
    return Promise.reject(error);
});

//设置响应拦截器
axios.interceptors.response.use(function (response) {

    return response;
}, function (error) {

    var status = error.response.status;
    if (status === 400) {
        alert("请求错误");
    }
    else if (status === 401) {
        alert("未登录")
    }
    else if (status === 404) {
        alert("资源未找到")
    }
    else if (status === 500) {
        alert("服务器错误")
    }


    return Promise.reject(error);
})

export default axios